package com.aipii.demo.rpcserver;

import com.alibaba.fastjson.JSONObject;
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@AutoJsonRpcServiceImpl
public class RpcUserServiceImpl implements RpcUserService {
	/**
	 * 查询多个产品
	 *
	 * @param size
	 * @return
	 */
	@Override
	public List<JSONObject> query(Integer size) {
		size = size == null || size < 10 ? 10 : size;
		List<JSONObject> users = new ArrayList<>();
		for (int i = 0; i < size; i++) {
			JSONObject user = new JSONObject();
			user.put("id", i);
			user.put("name", "lilei" + i);
			user.put("age", 20 + i);
			users.add(user);
		}
		return users;
	}
	
	/**
	 * 查询单个产品
	 *
	 * @param id
	 * @return
	 */
	@Override
	public JSONObject findOne(Integer id) {
		JSONObject user = new JSONObject();
		user.put("id", id);
		user.put("name", "lilei" + id);
		user.put("age", 20 + id);
		return user;
	}
	
	@Override
	public JSONObject find2(UserRequest userRequest) {
		JSONObject user = new JSONObject();
		user.put("id", userRequest.getId());
		user.put("name", "lilei" + userRequest.getName());
		user.put("age", "20" + userRequest.getAge());
		return user;
	}
}
